package com.sinoeyes.flowdata.service.impl;

import com.sinoeyes.common.core.page.RestPageResult;
import com.sinoeyes.common.core.text.Convert;
import com.sinoeyes.common.vo.BaseVo;
import com.sinoeyes.flowdata.po.FlowSalesDataPo;
import com.sinoeyes.flowdata.filter.FlowSalesDataFilter;
import com.sinoeyes.flowdata.mapper.FlowSalesDataMapper;
import com.sinoeyes.flowdata.service.IFlowSalesDataService;
import com.sinoeyes.flowdata.vo.FlowSalesDatasVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 标准销售流向Service业务层处理
 * 
 * @author steven.zhang
 * @date 2019-10-10
 */
@Service
public class FlowSalesDataServiceImpl implements IFlowSalesDataService
{
    @Autowired
    private FlowSalesDataMapper flowSalesDataMapper;

    /**
     * 查询标准销售流向
     * 
     * @param id 标准销售流向ID
     * @return 标准销售流向
     */
    @Override
    public FlowSalesDatasVo selectFlowSalesDatasById(String id)
    {
        return BaseVo.copyPo2Vo(flowSalesDataMapper.selectFlowSalesDatasById(id), FlowSalesDatasVo.class);
    }

    /**
     * 根据条件查询
     * @param flowSalesDataFilter 标准销售流向筛选条件
     * @return
     */
    @Override
    public RestPageResult<FlowSalesDatasVo> selectFlowSalesDatasByFilter(FlowSalesDataFilter flowSalesDataFilter) {
        flowSalesDataFilter.startPage();
        List<FlowSalesDataPo> flowSalesDataPos = flowSalesDataMapper.selectFlowSalesDatasByFilter(flowSalesDataFilter);
        RestPageResult pageResult = flowSalesDataFilter.getPageResult(flowSalesDataPos);
        return BaseVo.copyPo2Vo(pageResult, FlowSalesDatasVo.class);
    }

    /**
     * 新增标准销售流向
     * 
     * @param flowSalesDatasVo 标准销售流向
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int insertFlowSalesDatas(FlowSalesDatasVo flowSalesDatasVo)
    {
        return flowSalesDataMapper.insertFlowSalesDatas(BaseVo.copyVo2Po(flowSalesDatasVo, FlowSalesDataPo.class));
    }

    /**
     * 修改标准销售流向
     *
     * @param flowSalesDatasVo 标准销售流向
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int updateFlowSalesDatas(FlowSalesDatasVo flowSalesDatasVo)
    {
        return flowSalesDataMapper.updateFlowSalesDatas(BaseVo.copyVo2Po(flowSalesDatasVo, FlowSalesDataPo.class));
    }

    /**
     * 删除标准销售流向对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int deleteFlowSalesDatasByIds(String ids)
    {
        return flowSalesDataMapper.deleteFlowSalesDatasByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除标准销售流向信息
     * 
     * @param id 标准销售流向ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int deleteFlowSalesDatasById(String id)
    {
        return flowSalesDataMapper.deleteFlowSalesDatasById(id);
    }
}
